package cn.bellychang.leetcode.question257;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ChangLiang
 * @date 2021/2/8
 */
public class Solution {

    public List<String> binaryTreePaths(TreeNode root) {
        return traversePath(root);
    }

    private List<String> traversePath(TreeNode treeNode) {
        List<String> list = new ArrayList<>();
        if (treeNode == null) {
            return list;
        }
        if (treeNode.left == null && treeNode.right == null) {
            list.add(String.valueOf(treeNode.val));
            return list;
        }

        List<String> left = traversePath(treeNode.left);
        if (left.size() != 0) {
            for (String s : left) {
                list.add(treeNode.val + "->" + s);
            }
        }
        List<String> right = traversePath(treeNode.right);
        if (right.size() != 0) {
            for (String s : right) {
                list.add(treeNode.val + "->" + s);
            }
        }
        return list;
    }
}
